package com.shujia.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveJDBC {
    public static void main(String[] args) throws Exception{
        //加载驱动
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        //创建与hive的连接对象
        Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/bigdata29");
        //创建操作hive的对象
        Statement state = conn.createStatement();
        ResultSet resultSet = state.executeQuery("select empno,hiredate,sal,t1.deptno from emp t1 join dept t2 on(t1.deptno=t2.deptno)");
        while (resultSet.next()){
            String empno = resultSet.getString(1);
            String hiredate = resultSet.getString(2);
            String sal = resultSet.getString(3);
            String deptno = resultSet.getString(4);
            System.out.println(empno+", "+hiredate+", "+sal+", "+deptno);
        }
        //释放资源
        conn.close();
    }
}
